/*
 * PKL 51 GUNUNG KIDUL
 * Subseksie DATA ENTRY + CAPI
 */

/*
 * Home.java
 *
 * Created on 28 Feb 12, 23:08:46
 */
package pkl51.view;

import java.sql.*;
import javax.swing.JLabel;
import javax.swing.JTable;
import pkl51.component.TextField;
import pkl51.controller.HomeController;
import pkl51.database.DatabaseUtility;
import pkl51.model.HomeModel;
import pkl51.model.MahasiswaModel;

/**
 *
 * @author FITRI ANDRI ASTUTI
 */
public class Home extends javax.swing.JPanel {

    private HomeModel homeModel;
    private HomeController controller;

    public Home() {
        homeModel = HomeModel.getInstance();

        controller = new HomeController();
        controller.setModel(homeModel);

        initComponents();

    }

    public HomeController getController() {
        return controller;
    }

    public JLabel getLabelNamaKortim() {
        return labelNamaKortim;
    }

    public JLabel getLabelNamaPencacah() {
        return labelNamaPencacah;
    }

    public JLabel getLabelNimKortim() {
        return labelNimKortim;
    }

    public JLabel getLabelNimPencacah() {
        return labelNimPencacah;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        label1 = new pkl51.component.Label();
        jScrollPane1 = new pkl51.component.ScrollPane();
        labelNamaPencacah = new pkl51.component.Label();
        labelNamaKortim = new pkl51.component.Label();
        labelNimPencacah = new pkl51.component.Label();
        labelNimKortim = new pkl51.component.Label();

        label1.setText("Sampel Yang Sudah Dientry");
        label1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(65, 65, 65)
                                .addComponent(labelNamaKortim, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(210, 210, 210)
                                .addComponent(labelNamaPencacah, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(267, 267, 267)
                                .addComponent(labelNimPencacah, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(283, 283, 283)
                                .addComponent(labelNimKortim, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 161, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelNimPencacah, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelNamaPencacah, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelNamaKortim, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelNimKortim, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private pkl51.component.ScrollPane jScrollPane1;
    private pkl51.component.Label label1;
    private pkl51.component.Label labelNamaKortim;
    private pkl51.component.Label labelNamaPencacah;
    private pkl51.component.Label labelNimKortim;
    private pkl51.component.Label labelNimPencacah;
    // End of variables declaration//GEN-END:variables

    private Object[][] getData() {
        Object[][] data1 = null;
        try {
            Connection conn = DatabaseUtility.getConnection();
            Statement stmt = conn.createStatement();
            ResultSet rslt = stmt.executeQuery("Select * from ruta where nim_pengentri = " + MahasiswaModel.getInstance().getNim());
            rslt.last();
            int rowCount = rslt.getRow();
            rslt.beforeFirst();
            data1 = new Object[rowCount][7];
            int no = -1;
            while (rslt.next()) {
                no = no + 1;
                data1[no][0] = rslt.getString("NKS");
                data1[no][1] = rslt.getString("B1R2");
                data1[no][2] = rslt.getString("B1R3");
                data1[no][3] = rslt.getString("B1R4");
                data1[no][4] = rslt.getString("B1R5");
                data1[no][5] = rslt.getString("B1R6");
                data1[no][6] = rslt.getString("B1R8");
            }
            stmt.close();
            conn.close();
        } catch (SQLException e) {
            System.out.println("Koneksi keDatabase Gagal !!" + e.toString());
        }
        return data1;

    }

    public  void tampilTable() {
        String[] columnNames = {"NKS", "Kode Kecamatan", "Kode Desa", "No. BS", "No. Urut BS", "No. Urut Sampel RuTa", "Nama Kepala RuTa"};
        JTable table = new JTable(getData(), columnNames);
        jScrollPane1.setViewportView(table);

    }
}
